package com.yiyibook.util;


import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * 〈功能简述〉
 *
 * @author xun.gong@hand-china.com
 * @date 2019/10/14
 */
public class BookNum {

    public static String setBookNum(String bookNum){
        // TODO: 2019/10/14 处理生产书籍流水号
        String localDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        if(bookNum == null){
            bookNum = "BK" + localDate + "0001";
        }else {
            String s = bookNum.substring(2, 10);
            if(localDate.equals(s)){
                bookNum = "BK" + s + StringUtils.leftPad(String.valueOf((Integer.parseInt(bookNum.substring(10)) + 1)), 4,"0");
            }else {
                bookNum = "BK" + localDate + "0001";
            }
        }
        return bookNum;
    }
}
